﻿using DART.Detector.IRay.Wrapper;
using System.Collections.Generic;

namespace DART.Detector.IRay
{
    /// <summary>
    /// IRay 相关扩展方法
    /// </summary>
    public static partial class IRayExtensions
    {
        /// <summary>
        /// 设置工作目录
        /// </summary>
        /// <param name="param"></param>
        /// <param name="workDirectory"></param>
        public static void SetWorkDirectory(this IDetectorParam param, string workDirectory = "IRay/Config/Mammo1012X")
            => param["WorkDirectory"] = workDirectory;

        public static string GetWorkDirectory(this IDetectorParam param)
            => param["WorkDirectory"] as string;

        /// <summary>
        /// 设置Tomo采集数量
        /// </summary>
        /// <param name="param"></param>
        /// <param name="tomoFrame"></param>
        public static void SetTomoFrameNumber(this IDetectorParam param, int tomoFrame = 25)
            => param[nameof(IRayAttr.UROMContinuCapFrameNumW)] = tomoFrame;

        public static int GetTomoFrameNumber(this IDetectorParam param)
            => (int)param[nameof(IRayAttr.UROMContinuCapFrameNumW)];

        internal class DetectorParam : Dictionary<string, object>, IDetectorParam
        {
            public DetectorParam()
            {
                base["WorkDirectory"] = "IRay/Config/Mammo1012X"; // 默认工作目录
                //base[nameof(IRayAttr.UROMContinuCapFrameNumW)] = 25; // TOMO模式的帧数
                //base[nameof(IRayAttr.UROMFrameNumberW)] = 2; // 如果使用多帧叠加的帧数
                //base[nameof(IRayAttr.UROMHvgXRaySyncOutW)] = SignalLevel.High;
                //base[nameof(IRayAttr.UROMHvgPrepOnW)] = SignalLevel.Low;
                //base[nameof(IRayAttr.UROMHvgXRayEnableW)] = SignalLevel.Low;
                //base[nameof(IRayAttr.UROMHvgXRayOnW)] = SignalLevel.Low;
            }
        }

        internal static AppMode Swap(this DetectorMode mode)
        {
            switch (mode)
            {
                case DetectorMode.Contact:
                    return AppMode.Contact;

                case DetectorMode.Mag:
                    return AppMode.Magnification;

                case DetectorMode.Stereo:
                    return AppMode.Stereo;

                case DetectorMode.Tomo:
                    return AppMode.Tomo;

                default:
                    return (AppMode)mode;
            }
        }

        internal static DetectorMode Swap(this AppMode appMode)
        {
            switch (appMode)
            {
                case AppMode.Contact:
                    return DetectorMode.Contact;

                case AppMode.Magnification:
                    return DetectorMode.Mag;

                case AppMode.Stereo:
                    return DetectorMode.Stereo;

                case AppMode.Tomo:
                    return DetectorMode.Tomo;

                default:
                    return (DetectorMode)appMode;
            }
        }
    }

}